<template>
  <el-dialog
    :title="!dataForm.adId ? '新增' : '修改'"
    :close-on-click-modal="false"
    :visible.sync="visible"
    append-to-body>
    <el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()" label-width="80px">
    <el-form-item label="用户名" prop="adUserName">
      <el-input v-model="dataForm.adUserName" id="adUserName" placeholder="用户名"></el-input>
    </el-form-item>
    <el-form-item label="密码" prop="adUserPassword">
      <el-input  v-model="dataForm.adUserPassword" id="adUserPassword" placeholder="密码" show-password></el-input>
    </el-form-item>
<!--    <el-form-item label="创建时间" prop="adCreationTime">-->
<!--      <el-input v-model="dataForm.adCreationTime" id="adCreationTime" placeholder="创建时间"></el-input>-->
<!--    </el-form-item>-->
<!--    <el-form-item label="更新时间" prop="adUpdateTime">-->
<!--      <el-input v-model="dataForm.adUpdateTime" id="adUpdateTime" placeholder="更新时间"></el-input>-->
<!--    </el-form-item>-->
<!--    <el-form-item label="状态" prop="adStatus">-->
<!--      <el-input v-model="dataForm.adStatus" id="adStatus" disabled="disabled" placeholder="状态"></el-input>-->
<!--    </el-form-item>-->
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" @click="dataFormSubmit()">确定</el-button>
    </span>
  </el-dialog>
</template>

<script>
  export default {
    data () {
      return {
        visible: false,
        dataForm: {
          adId: 0,
          adUserName: '',
          adUserPassword: '',
          // adCreationTime: '',
          // adUpdateTime: '',
          // adStatus: ''
        },
        disabled: "",
        dataRule: {
          adUserName: [
            { required: true, message: '用户名不能为空', trigger: 'blur' }
          ],
          adUserPassword: [
            { required: true, message: '密码不能为空', trigger: 'blur' }
          ],
          adCreationTime: [
            { required: true, message: '创建时间不能为空', trigger: 'blur' }
          ],
          adUpdateTime: [
            { required: true, message: '更新时间不能为空', trigger: 'blur' }
          ],
          adStatus: [
            { required: true, message: '状态不能为空', trigger: 'blur' }
          ]
        }
      }
    },
    methods: {
      init (id) {
        this.dataForm.adId = id || 0
        this.visible = true
        this.$nextTick(() => {
          this.$refs['dataForm'].resetFields()
          if (this.dataForm.adId) {
            this.$http({
              url: this.$http.adornUrl(`/fiction/tbadmin/info/${this.dataForm.adId}`),
              method: 'get',
              params: this.$http.adornParams()
            }).then(data => {
              if (data && data.code === 200) {
                this.dataForm.adUserName = data.tbAdmin.adUserName
                this.dataForm.adUserPassword = data.tbAdmin.adUserPassword
                // this.dataForm.adCreationTime = data.tbAdmin.adCreationTime
                // this.dataForm.adUpdateTime = data.tbAdmin.adUpdateTime
                // this.dataForm.adStatus = data.tbAdmin.adStatus
              }
            })
          }
        })
      },
      // 表单提交
      dataFormSubmit () {
        this.$refs['dataForm'].validate((valid) => {
          if (valid) {
            this.$http({
              url: this.$http.adornUrl(`/fiction/tbadmin/${!this.dataForm.adId ? 'save' : 'update'}`),
              method: 'post',
              data: this.$http.adornData({
                'adId': this.dataForm.adId || undefined,
                'adUserName': this.dataForm.adUserName,
                'adUserPassword': this.dataForm.adUserPassword,
                // 'adCreationTime': this.dataForm.adCreationTime,
                // 'adUpdateTime': this.dataForm.adUpdateTime,
                // 'adStatus': this.dataForm.adStatus
              })
            }).then((data) => {
              if (data && data.code === 200) {
                this.$message({
                  message: '操作成功',
                  type: 'success',
                  duration: 1500,
                  onClose: () => {
                    this.visible = false
                    this.$emit('refreshDataList')
                  }
                })
              } else {
                this.$message.error(data.msg)
              }
            })
          }
        })
      }
    }
  }
</script>
